# -*- coding: utf-8 -*-
import maya.cmds as cmds
import maya.mel as mel
import sys
#reload(sys)
#sys.setdefaultencoding('utf-8')
class Check_Export_Cam_FBX():
	def Cam_Bake(self,Endings,Exp_Path):
		file_path = cmds.file(q=True, sceneName=True)
		file_name = file_path.split('/')[-1]
		file_name= file_name.split('.')
		CamShapeTmps = ['front' , 'persp' , 'side' , 'top']
		AllCamShapes = cmds.listCameras()
		ListCam = list ( set ( AllCamShapes ) ^ set ( CamShapeTmps ) )
		if len (ListCam ) == 1 :
			Old_Cam = cmds.ls(ListCam)[0]
			New_CamName = Old_Cam + Endings
			New_Cam = cmds.rename(cmds.camera()[0], New_CamName)
			cmds.parentConstraint(Old_Cam,New_Cam,name =New_Cam+'Constraint')
			New_Cam_shape = cmds.listRelatives (New_Cam,shapes=True,children=True)[0]
			Old_Cam_shape = cmds.listRelatives (Old_Cam,shapes=True,children=True)[0]
			cmds.connectAttr(Old_Cam_shape+".focalLength",New_Cam_shape+".focalLength")
			st = cmds.playbackOptions(min=1, q=1)
			et = cmds.playbackOptions(max=1, q=1)
			cmds.select(New_Cam,replace=True)
			cmds.bakeResults(New_Cam, t=(st, et), sb=1)
			
			Export_Path = Exp_Path.replace('\\', '/')+ '/'+ file_name[0] +'_cam.fbx'
			mel.eval("FBXResetExport; "
			"FBXExportInputConnections -v false; "
			"FBXExportBakeComplexAnimation -v false; "
			"FBXExportLights -v false; "
			"FBXExportCameras -v true; "
			"FBXExportInAscii -v true;"
			"FBXExportFileVersion FBX201700;"
			"FBXExportSmoothingGroups -v true; "
			"FBXExportSmoothMesh -v true;"
			"FBXExportApplyConstantKeyReducer -v false;"
			"FBXExportBakeComplexAnimation -v true; "
			"FBXExportBakeComplexStep -v true; "
			"FBXExportCameras -v true;")
			mel.eval(('FBXExport -f \"{}\" -s').format(Export_Path))
			cmds.delete(cmds.ls(New_Cam))
			return("YES")
		else:
			return("NO")